{% extends 'base.html' %}
{% block content %}
<body>
<script type="text/javascript" src="/ue/ueditor.config.js"></script>
<script type="text/javascript" src="/ue/ueditor.all.min.js"></script>
<script type="text/javascript" src="/ue/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    var ue = UE.getEditor('content',{
            initialFrameHeight: 400,
            autoHeightEnabled: true,
            serverUrl:'/uedit',
        });
</script>

<div class="container" style="margin-top: 20px; background-color: white; padding: 20px;">
    <div class="row form-group">
        <label for="headline" class="col-1">文章标题</label>
        <input type="text" class="col-11" id="headline"/>
    </div>
    <div class="row">
        <script id="content" name="content" type="text/plain"></script>
    </div>
    <div class="row form-group" style="margin-top: 20px; padding-top: 10px;">
        <label for="type" class="col-1">类型:</label>
        <select class="form-control col-2" id="type" style="width: 250px">
            <option value="1">PHP开发</option>
            <option value="2">Java开发</option>
            <option value="3">Python开发</option>
            <option value="4">Web前端</option>
            <option value="5">测试开发</option>
            <option value="6">数据科学</option>
            <option value="7">网络安全</option>
            <option value="8">蜗牛杂谈</option>
        </select>
        <label class="col-1"></label>
        <label for="credit" class="col-1">积分:</label>
        <select class="form-control col-2" id="credit" style="width: 250px">
            <option value="0">0分</option>
            <option value="1">1分</option>
            <option value="2">2分</option>
            <option value="5">5分</option>
            <option value="10">10分</option>
            <option value="20">20分</option>
            <option value="50">50分</option>
        </select>

        <label class="col-1"></label>
        <button class="form-comtrol btn-default col-2">保存发布</button>
        <button class="form-comtrol btn-primary col-2" onclick="doUserPost()">发布文章</button>
    </div>

<script>
    function doUserPost(){
        var headline= $("#headline").val().trim();
        var contentPlain = UE.getEditor("content").getContentTxt();
        var type = $("#type").val();
        var credit = $("#credit").val();

        var param = "headline="+headline;
        param += "&credit="+credit;
        param += "&type="+type;
        param += "&content="+contentPlain;
        $.post('/add_article', param, function (data){
            if(data == "OK"){
             location.href = "/";
         }
            else{
             alert("文章发布失败")
         }

        })
    }
</script>
</div>
</body>
{% endblock %}